using SqlQueryBuilder.Clauses;
using SqlQueryBuilder.Criterias;

namespace SqlQueryBuilder.Queries
{
    /// <summary>
    /// Delete Query
    /// </summary>
    public class DeleteQuery : IDeleteQuery
    {
        private readonly DeleteCriteria deleteCriteria;
        private readonly Where whereClause;

        /// <summary>
        /// Initializes a new instance of the <see cref="DeleteQuery"/> class.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        public DeleteQuery(string tableName)
        {
            deleteCriteria = new DeleteCriteria(tableName);
            whereClause = new Where();
        }

        /// <summary>
        /// Wheres the specified clause.
        /// </summary>
        /// <param name="clause">The clause.</param>
        /// <returns></returns>
        public IWhereQuery Where(IConditionalClause clause)
        {
            whereClause.whereclause = clause;
            return this;
        }

        /// <summary>
        /// Builds the query.
        /// </summary>
        /// <returns></returns>
        public string BuildQuery()
        {
            return deleteCriteria.BuildCriteria() + whereClause.BuildCriteria();
        }
    }
}